#!/bin/bash

set -e
pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
function exit_trap() {
    popd > /dev/null
}
trap exit_trap EXIT

bold() {
    echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
}

clean() {
    bold "deeplearning4j clean"
    rm -rf "./third_party/src/dl4j"
}

sync() {
    bold "deeplearning4j sync"
    [ -d "./third_party/src/dl4j" ] || git clone --quiet https://github.com/eclipse/deeplearning4j.git "./third_party/src/dl4j"
    pushd "./third_party/src/dl4j" > /dev/null
    git pull --quiet --prune
    popd > /dev/null
}

while [ "$#" != 0 ]; do
    command="$1" && shift
    case "${command}" in
        "clean") clean;;
        "sync") sync;;
    esac
done
